//
//  SettingInputView.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/16.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "SettingInputView.h"

@interface SettingInputView()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *submitButton;

@end

@implementation SettingInputView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self makeSettingInputView];
        
    }
    return self;
}

- (void)makeSettingInputView
{
    _titleLabel = [UILabel new];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.textColor = [UIColor blackColor];
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.mas_equalTo(0);
        make.width.mas_equalTo(40);
    }];
    
    _submitButton = [UIButton new];
    [_submitButton setTitle:@"提交" forState:UIControlStateNormal];
    [_submitButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _submitButton.layer.masksToBounds = YES;
    _submitButton.layer.borderWidth = 1.0;
    _submitButton.layer.borderColor = [RGB(220, 220, 220) CGColor];
    _submitButton.layer.cornerRadius = 5.0;
    [_submitButton addTarget:self action:@selector(clickSubmitButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_submitButton];
    [_submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(70, 30));
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(0);
    }];
    
    UIView *bgView = [UIView new];
    bgView.layer.masksToBounds = YES;
    bgView.layer.borderColor = [[UIColor blackColor] CGColor];
    bgView.layer.borderWidth = 1.0;
    bgView.layer.cornerRadius = 10;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(-5);
        make.left.mas_equalTo(_titleLabel.mas_right).mas_offset(20);
        make.right.mas_equalTo(_submitButton.mas_left).mas_offset(-20);
    }];
    
    _field = [UITextField new];
    [bgView addSubview:_field];
    [_field mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
    }];
    
}

- (void)setLabelTitle:(NSString *)labelTitle
{
    _titleLabel.text = labelTitle;
}

- (void)setPlaceholder:(NSString *)placeholder
{
    _field.placeholder = placeholder;
}

- (void)clickSubmitButton:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(clickSubmit:inputText:)]) {
        [self.delegate clickSubmit:self inputText:_field.text];
    }
}


@end
